from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-01 14:07:08.323676
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 01, Feb, 2022
Time: 14:07:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9380
Nobs: 554.000 HQIC: -48.3653
Log likelihood: 6488.27 FPE: 7.52012e-22
AIC: -48.6393 Det(Omega_mle): 6.40178e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349156 0.069628 5.015 0.000
L1.Burgenland 0.106442 0.042278 2.518 0.012
L1.Kärnten -0.110614 0.021964 -5.036 0.000
L1.Niederösterreich 0.197420 0.088408 2.233 0.026
L1.Oberösterreich 0.131563 0.087371 1.506 0.132
L1.Salzburg 0.254442 0.044688 5.694 0.000
L1.Steiermark 0.034713 0.058931 0.589 0.556
L1.Tirol 0.098142 0.047582 2.063 0.039
L1.Vorarlberg -0.071861 0.042051 -1.709 0.087
L1.Wien 0.017927 0.077771 0.231 0.818
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054701 0.150848 0.363 0.717
L1.Burgenland -0.041077 0.091593 -0.448 0.654
L1.Kärnten 0.040495 0.047584 0.851 0.395
L1.Niederösterreich -0.203735 0.191534 -1.064 0.287
L1.Oberösterreich 0.454975 0.189286 2.404 0.016
L1.Salzburg 0.283403 0.096815 2.927 0.003
L1.Steiermark 0.115857 0.127672 0.907 0.364
L1.Tirol 0.305985 0.103084 2.968 0.003
L1.Vorarlberg 0.023018 0.091103 0.253 0.801
L1.Wien -0.024103 0.168489 -0.143 0.886
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194982 0.035396 5.509 0.000
L1.Burgenland 0.090940 0.021492 4.231 0.000
L1.Kärnten -0.007401 0.011165 -0.663 0.507
L1.Niederösterreich 0.236368 0.044943 5.259 0.000
L1.Oberösterreich 0.168127 0.044415 3.785 0.000
L1.Salzburg 0.038488 0.022717 1.694 0.090
L1.Steiermark 0.025755 0.029958 0.860 0.390
L1.Tirol 0.080760 0.024188 3.339 0.001
L1.Vorarlberg 0.055286 0.021377 2.586 0.010
L1.Wien 0.118383 0.039535 2.994 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118062 0.035534 3.322 0.001
L1.Burgenland 0.043531 0.021576 2.018 0.044
L1.Kärnten -0.013810 0.011209 -1.232 0.218
L1.Niederösterreich 0.172143 0.045118 3.815 0.000
L1.Oberösterreich 0.335125 0.044589 7.516 0.000
L1.Salzburg 0.099707 0.022806 4.372 0.000
L1.Steiermark 0.109606 0.030075 3.644 0.000
L1.Tirol 0.090484 0.024283 3.726 0.000
L1.Vorarlberg 0.060611 0.021461 2.824 0.005
L1.Wien -0.015755 0.039690 -0.397 0.691
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125362 0.067088 1.869 0.062
L1.Burgenland -0.047933 0.040735 -1.177 0.239
L1.Kärnten -0.045495 0.021162 -2.150 0.032
L1.Niederösterreich 0.141089 0.085183 1.656 0.098
L1.Oberösterreich 0.165898 0.084183 1.971 0.049
L1.Salzburg 0.283978 0.043058 6.595 0.000
L1.Steiermark 0.058617 0.056781 1.032 0.302
L1.Tirol 0.155486 0.045846 3.392 0.001
L1.Vorarlberg 0.093910 0.040517 2.318 0.020
L1.Wien 0.072436 0.074934 0.967 0.334
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079922 0.052309 1.528 0.127
L1.Burgenland 0.023666 0.031761 0.745 0.456
L1.Kärnten 0.053300 0.016500 3.230 0.001
L1.Niederösterreich 0.192896 0.066417 2.904 0.004
L1.Oberösterreich 0.329122 0.065638 5.014 0.000
L1.Salzburg 0.033577 0.033572 1.000 0.317
L1.Steiermark 0.003326 0.044272 0.075 0.940
L1.Tirol 0.119891 0.035746 3.354 0.001
L1.Vorarlberg 0.066764 0.031591 2.113 0.035
L1.Wien 0.099328 0.058426 1.700 0.089
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173371 0.063234 2.742 0.006
L1.Burgenland 0.004110 0.038395 0.107 0.915
L1.Kärnten -0.065501 0.019947 -3.284 0.001
L1.Niederösterreich -0.109022 0.080289 -1.358 0.175
L1.Oberösterreich 0.213764 0.079347 2.694 0.007
L1.Salzburg 0.052934 0.040584 1.304 0.192
L1.Steiermark 0.250710 0.053519 4.685 0.000
L1.Tirol 0.498119 0.043212 11.527 0.000
L1.Vorarlberg 0.064304 0.038190 1.684 0.092
L1.Wien -0.079229 0.070629 -1.122 0.262
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156428 0.069968 2.236 0.025
L1.Burgenland -0.003982 0.042484 -0.094 0.925
L1.Kärnten 0.062155 0.022071 2.816 0.005
L1.Niederösterreich 0.182006 0.088840 2.049 0.040
L1.Oberösterreich -0.066209 0.087797 -0.754 0.451
L1.Salzburg 0.205166 0.044906 4.569 0.000
L1.Steiermark 0.139179 0.059218 2.350 0.019
L1.Tirol 0.056182 0.047814 1.175 0.240
L1.Vorarlberg 0.142747 0.042257 3.378 0.001
L1.Wien 0.129692 0.078150 1.660 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395338 0.040837 9.681 0.000
L1.Burgenland -0.002631 0.024796 -0.106 0.915
L1.Kärnten -0.020661 0.012882 -1.604 0.109
L1.Niederösterreich 0.202255 0.051852 3.901 0.000
L1.Oberösterreich 0.240138 0.051243 4.686 0.000
L1.Salzburg 0.033744 0.026210 1.287 0.198
L1.Steiermark -0.017566 0.034563 -0.508 0.611
L1.Tirol 0.087100 0.027907 3.121 0.002
L1.Vorarlberg 0.050914 0.024663 2.064 0.039
L1.Wien 0.034921 0.045613 0.766 0.444
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035299 0.102898 0.166697 0.133324 0.094350 0.081414 0.029453 0.211954
Kärnten 0.035299 1.000000 -0.025292 0.133345 0.046834 0.086645 0.444539 -0.068427 0.093211
Niederösterreich 0.102898 -0.025292 1.000000 0.309887 0.124929 0.267950 0.068407 0.156939 0.281953
Oberösterreich 0.166697 0.133345 0.309887 1.000000 0.214859 0.293672 0.169987 0.134169 0.236136
Salzburg 0.133324 0.046834 0.124929 0.214859 1.000000 0.124676 0.089967 0.103614 0.127866
Steiermark 0.094350 0.086645 0.267950 0.293672 0.124676 1.000000 0.134715 0.106116 0.029758
Tirol 0.081414 0.444539 0.068407 0.169987 0.089967 0.134715 1.000000 0.063430 0.151791
Vorarlberg 0.029453 -0.068427 0.156939 0.134169 0.103614 0.106116 0.063430 1.000000 -0.004950
Wien 0.211954 0.093211 0.281953 0.236136 0.127866 0.029758 0.151791 -0.004950 1.000000